<template>
  <div class="container">
    <el-card>
      <div class="btn-wrapper">
        <span>说明: 目前支持学科和关键字条件筛选</span>
        <el-button type="success" size="mini" @click="$router.push('new')">
          <i class="el-icon-edit"></i>
          新增试题
        </el-button>
      </div>
      <!-- 搜索模块 -->
      <el-form
        :inline="true"
        :model="requestParameters"
        ref="requestParameters"
        class="demo-form-inline"
        label-position="right"
        label-width="110px"
      >
        <el-row>
          <el-col :span="6">
            <el-form-item label="学科" prop="subjectID">
              <el-select
                v-model="requestParameters.subjectID"
                @change="handleSubjectChange"
                placeholder="请选择"
                style="width: 100%;"
              >
                <el-option v-for="item in subjectList" :label="item.label" :value="item.value"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="二级目录" prop="catalogID">
              <el-select v-model="requestParameters.catalogID" placeholder="请选择">
                <el-option v-for="item in catalogData" :label="item.directoryName" :value="item.id"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="标签" prop="tags">
              <el-select v-model="requestParameters.tags" placeholder="请选择">
                <el-option v-for="item in tagList" :label="item.tagName" :value="item.id"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="关键字" prop="keyword">
              <el-input v-model="requestParameters.keyword" placeholder="根据题干搜索"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="6">
            <el-form-item label="试题类型" prop="questionType">
              <el-select v-model="requestParameters.questionType" placeholder="请选择">
                <el-option v-for="item in questionType" :label="item.label" :value="item.value"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="难度" prop="difficulty">
              <el-select v-model="requestParameters.difficulty" placeholder="请选择">
                <el-option
                  v-for="diffItem in difficulty"
                  :label="diffItem.label"
                  :value="diffItem.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="方向" prop="direction">
              <el-select v-model="requestParameters.direction" placeholder="请选择">
                <el-option v-for="direItem in direction" :label="direItem" :value="direItem"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="录入人" prop="creatorID">
              <el-select v-model="requestParameters.creatorID" placeholder="请选择">
                <el-option v-for="item in userList" :label="item.username" :value="item.id"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="6">
            <el-form-item label="题目备注" prop="remarks">
              <el-input v-model="requestParameters.remarks"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="企业简称" prop="shortName">
              <el-input v-model="requestParameters.shortName"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-row>
              <el-col :span="15">
                <el-form-item label="城市" prop="province">
                  <el-select
                    v-model="requestParameters.province"
                    @change="handleProvince"
                    placeholder="请选择"
                  >
                    <el-option
                      v-for="item in citySelect.province"
                      :label="item"
                      :value="item"
                      :key="item"
                    ></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="9">
                <el-form-item prop="city" class="city">
                  <el-select v-model="requestParameters.city" placeholder="请选择">
                    <el-option
                      v-for="item in citySelect.cityData"
                      :key="item"
                      :label="item"
                      :value="item"
                    ></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
          </el-col>
          <el-col :span="6" style="text-align:right;">
            <el-button size="mini" @click="resetForm">清除</el-button>
            <el-button type="primary" size="mini" @click="handleFilter">搜索</el-button>
          </el-col>
        </el-row>
      </el-form>
      <div>
        <el-alert :title="alertText" type="info" show-icon :closable="false"></el-alert>
      </div>
      <!-- 数据列表 -->
      <el-table
        :key="tableKey"
        :data="dataList"
        v-loading="listLoading"
        element-loading-text="给我一点时间"
        highlight-current-row
        style="width: 100%"
      >
        <el-table-column prop="number" label="试题编号" width="120"></el-table-column>
        <el-table-column prop="subjectID" label="学科" min-width="70" :formatter="formatterSubject"></el-table-column>
        <el-table-column prop="catalogID" label="目录" :formatter="formatterCatalog"></el-table-column>
        <el-table-column prop="questionType" label="题型" min-width="70" :formatter="formatterType"></el-table-column>
        <el-table-column prop="question" label="题干" min-width="150">
          <template v-slot="{row}">
            <span v-html="row.question"></span>
          </template>
        </el-table-column>
        <el-table-column prop="addDate" label="录入时间" min-width="150" :formatter="formatterTime"></el-table-column>
        <el-table-column prop="difficulty" label="难度" min-width="70" :formatter="formatterDiff"></el-table-column>
        <el-table-column prop="creator" min-width="100" label="录入人"></el-table-column>
        <!-- 操作按钮 -->
        <el-table-column label="操作" width="200" class-name="small-padding fixed-width">
          <template v-slot="{row}">
            <!-- <el-tooltip :transition="false" content="预览" placement="bottom" effect="light">
              <el-button plain type="primary" icon="el-icon-document" circle></el-button>
            </el-tooltip>-->
            <el-button plain type="primary" icon="el-icon-document" circle
            @click="hanldePreviewQuestion(row.id)"></el-button>
            <el-button
              plain
              type="success"
              icon="el-icon-edit"
              circle
              @click="$router.push({ name: 'questions-new', query: { id: row.id } })"
            ></el-button>
            <el-button
              plain
              type="warning"
              icon="el-icon-star-off"
              circle
              @click="choiceQuestion(row.id)"
            ></el-button>
            <el-button
              plain
              type="danger"
              icon="el-icon-delete"
              circle
              @click="removeQuestion(row.id)"
            ></el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- end -->
      <!-- 分页 -->
      <div class="pagination">
        <div class="pages">
          <el-pagination
            background
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="Number(requestParameters.page)"
            :total="Number(total)"
            :page-size="Number(requestParameters.pagesize)"
            :page-sizes="[2,5,7, 10]"
            layout="sizes, prev, pager, next, jumper"
          ></el-pagination>
        </div>
      </div>
      <!-- end -->
      <!-- 预览弹层 -->
      <preview-dialog v-if="previewQes" ref="previewQuestion"
      :formBase="formData"></preview-dialog>
    </el-card>
  </div>
</template>

<script src="./js/questions.js"></script>

<style scoped lang='less'>
@import url("./style/questions.less");
</style>
